﻿using HastyAPI.Nexmo;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;

namespace Zatify.API
{
    public class SmsSendService
    {
        public SmsSendService()
        {
        }

        public static string NexmoKey
        {
            get { return ConfigurationManager.AppSettings.Get("NexmoKey"); }
        }

        public static bool NexmoEnabled
        {
            get { return bool.Parse(ConfigurationManager.AppSettings.Get("NexmoEnabled")); }
        }

        public static string NexmoSecret
        {
            get { return ConfigurationManager.AppSettings.Get("NexmoSecret"); }
        }

        public static string NexmoFrom
        {
            get { return ConfigurationManager.AppSettings.Get("NexmoFrom"); }
        }

        public static bool SendSms(string message, string phone)
        {
            try
            {
                if (NexmoEnabled)
                {
                    var nexmo = new Nexmo(NexmoKey, NexmoSecret);
                    var response = nexmo.Send(NexmoFrom, phone, message);
                    return true;
                }

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        /*public  string GenerateCode()
        {
            if (NexmoEnabled == false) return "1111";
            Random codeGen = new Random();
            var result = codeGen.Next(8999) + 1000;
            return result.ToString();
        }*/
    }
}
